home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 9.9 KB | 378 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: LineShp.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef CONSTANT_H
- #include "Constant.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWTXTBOX_H
- #include "FWTxtBox.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWOVLSHP_H
- #include "FWOvlShp.h"
- #endif
-
- #ifndef FWRRCSHP_H
- #include "FWRRcShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdrawshapes
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- FW_DEFINE_AUTO(CLineShape)
- FW_DEFINE_CLASS_M1(CLineShape, CBaseShape)
-
- const FW_ClassTypeConstant LLineShape = FW_TYPE_CONSTANT('s','h','l','n');
- FW_REGISTER_ARCHIVABLE_CLASS(LLineShape, CLineShape, CLineShape::Read, 0, 0, CBaseShape::Write)
-
- //========================================================================================
- // class CLineShape
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CLineShape::CLineShape
- //----------------------------------------------------------------------------------------
-
- CLineShape::CLineShape() :
- CBaseShape(2, kLineShape, kFrameOnly)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::CLineShape
- //----------------------------------------------------------------------------------------
-
- CLineShape::CLineShape(FW_CReadableStream& archive) :
- CBaseShape(archive)
- {
- archive >> fStart;
- archive >> fEnd;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::~CLineShape
- //----------------------------------------------------------------------------------------
-
- CLineShape::~CLineShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::RenderShape
- //----------------------------------------------------------------------------------------
-
- void CLineShape::RenderShape(Environment* ev, ODFacet* facet, FW_CGraphicContext& gc)
- {
- FW_CLineShape::RenderLine(gc, fStart, fEnd, fFrameInk, fFrameStyle);
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::OutlineShape
- //----------------------------------------------------------------------------------------
-
- void CLineShape::OutlineShape(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style,
- const FW_CPoint& pt1, const FW_CPoint& pt2)
- {
- FW_CLineShape::RenderLine(gc, pt1, pt2, ink, style);
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CLineShape::HitTest(Environment *ev, FW_CGraphicContext& gc, const FW_CMouseEvent& theMouseEvent) const
- {
- // We should convert the point to shape coordinate
- FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
- frame->GetContentView(ev)->FrameToViewContent(ev, mouse);
-
- FW_CLineShape lineShape(fStart.x, fStart.y, fEnd.x, fEnd.y);
- return lineShape.HitTest(gc, mouse, FW_IntToFixed(2));
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::GetClipRegion
- //----------------------------------------------------------------------------------------
-
- void CLineShape::GetClipRegion(Environment* ev, ODShape* clipRegion)
- {
- ODShape* lineShape = ::FW_CreateLineODShape(ev, fStart, fEnd, GetPenSize());
- clipRegion->CopyFrom(ev, lineShape);
- lineShape->Release(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::CreateShapeOutline
- //----------------------------------------------------------------------------------------
-
- ODShape* CLineShape::CreateShapeOutline(Environment *ev)
- {
- ODShape* dragShape = ::FW_NewODShape(ev); // We don't acquire it because we return it
- GetClipRegion(ev, dragShape);
- return dragShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::GetHandleCenter
- //----------------------------------------------------------------------------------------
-
- void CLineShape::GetHandleCenter(short whichHandle, FW_CPoint& center) const
- {
- center = whichHandle == kInTopLeftCorner ? fStart : fEnd;
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::ResizeFeedback
- //----------------------------------------------------------------------------------------
-
- void CLineShape::ResizeFeedback(FW_CGraphicContext& gc, const FW_CInk& ink, const FW_CStyle& style,
- short whichHandle, const FW_CPoint& mouseLoc)
- {
- FW_CRect srcRect, dstRect;
- GetMapRects(whichHandle, mouseLoc, srcRect, dstRect);
-
- FW_CPoint pt1(fStart);
- FW_CPoint pt2(fEnd);
-
- pt1.Map(srcRect, dstRect);
- pt2.Map(srcRect, dstRect);
-
- if (srcRect.left == srcRect.right)
- {
- pt1.x = dstRect.left;
- pt2.x = dstRect.right;
- }
-
- if (srcRect.top == srcRect.bottom)
- {
- pt1.y = dstRect.top;
- pt2.y = dstRect.bottom;
- }
-
- OutlineShape(gc, ink, style, pt1, pt2);
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::GetMapRects
- //----------------------------------------------------------------------------------------
-
- void CLineShape::GetMapRects(short whichHandle, const FW_CPoint& mouseLoc,
- FW_CRect& srcRect, FW_CRect& dstRect)
- {
- srcRect.Set(fStart.x, fStart.y, fEnd.x, fEnd.y);
- dstRect = srcRect;
-
- switch (whichHandle)
- {
- case kInTopLeftCorner:
- dstRect.left = mouseLoc.x;
- dstRect.top = mouseLoc.y;
- break;
- case kInBottomRightCorner:
- dstRect.right = mouseLoc.x;
- dstRect.bottom = mouseLoc.y;
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::MapShape
- //----------------------------------------------------------------------------------------
-
- void CLineShape::MapShape(Environment *ev, CDrawPart* part, const FW_CRect& srcRect, const FW_CRect& dstRect)
- {
- FW_UNUSED(srcRect);
-
- CheckPromise(ev, part);
-
- ClearCache();
-
- FW_CRect realSrcRect;
- realSrcRect[FW_kTopLeft] = fStart;
- realSrcRect[FW_kBotRight] = fEnd;
-
- fStart.Map(realSrcRect, dstRect);
- fEnd.Map(realSrcRect, dstRect);
-
- if (realSrcRect.left == realSrcRect.right)
- {
- fStart.x = dstRect.left;
- fEnd.x = dstRect.right;
- }
-
- if (realSrcRect.top == realSrcRect.bottom)
- {
- fStart.y = dstRect.top;
- fEnd.y = dstRect.bottom;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::OffsetShape
- //----------------------------------------------------------------------------------------
-
- void CLineShape::OffsetShape(Environment *ev, FW_Fixed xDelta, FW_Fixed yDelta)
- {
- ClearCache();
-
- fStart.x += xDelta;
- fStart.y += yDelta;
-
- fEnd.x += xDelta;
- fEnd.y += yDelta;
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::SetShapeGeometry
- //----------------------------------------------------------------------------------------
-
- void CLineShape::SetShapeGeometry(const FW_CPoint& anchorPoint, const FW_CPoint& currentPoint)
- {
- fStart = anchorPoint;
- fEnd = currentPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void CLineShape::Flatten(FW_CWritableStream& archive)
- {
- CBaseShape::Flatten(archive);
-
- archive << fStart;
- archive << fEnd;
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::Read
- //----------------------------------------------------------------------------------------
-
- void* CLineShape::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
- {
- FW_UNUSED(type);
- return FW_NEW(CLineShape, (stream));
- }
-
- //----------------------------------------------------------------------------------------
- // CLineShape::GetRectGeometry
- //----------------------------------------------------------------------------------------
-
- FW_CRect CLineShape::GetRectGeometry() const
- {
- FW_CRect rect(fStart, fEnd);
- rect.Sort();
- return rect;
- }
-
-